var byYear=[15935661747, 17776799142, 22702691898, 21633298641, 19758635212, 18343496280, 21567594302, 16138756655, 15967618810, 12040583978, 11749224644, 11491191341, 12975881572, 10176291141, 8499494555, 10460508068, 13187844838, 10392615028, 11499211086, 10545329318, 10393502100, 9737521527, 9866386426, 10036403527, 10439375213, 14685407397, 13174544122, 11572592944, 9423914079, 9941252860, 10299696429, 10633697754, 9466594757, 10485474608, 11096816914, 9486259495, 7984153849, 7586437938, 8707122157, 11368216933, 11928965441, 10244260402, 11728913663, 16926140735, 22196581876, 24734206765, 21745122219, 20796128960, 25182008939, 24519555058, 27428706067
];

//converts a number to money format
//adapted from: http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript
Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep)
{ 
   var n = this,
   c = isNaN(decimals) ? 0 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
   d = decimal_sep || '.', //if no decimal separetor is passed we use the comma as default decimal separator (we MUST use a decimal separator)

   /*
   according to [http://stackoverflow.com/questions/411352/how-best-to-determine-if-an-argument-is-not-sent-to-the-javascript-function]
   the fastest way to check for not defined parameter is to use typeof value === 'undefined' 
   rather than doing value === undefined.
   */   
   t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, //if you don't want ot use a thousands separator you can pass empty string as thousands_sep value

   sign = (n < 0) ? '-' : '',

   //extracting the absolute value of the integer part of the number and converting to string
   i = parseInt(n = Math.abs(n).toFixed(c)) + '', 

   j = ((j = i.length) > 3) ? j % 3 : 0; 
   return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ''); 
}


//draws the bar above the year slider
$(function() {

var sliderBarWidth=14, sliderBarGraphWidth=836, sliderBarHeight=60;

var sliderBarX = d3.scale.linear().domain([0, byYear.length]).range([0, sliderBarGraphWidth]);
var sliderBarY = d3.scale.linear().domain([0, d3.max(byYear, function(datum) { return datum; })]).
  rangeRound([0, sliderBarHeight]);


  
var yearBarChart=d3.select("#sliderbars").append("svg:svg").
  attr("width", sliderBarGraphWidth).
  attr("height", sliderBarHeight);
;  




yearBarChart.selectAll("rect")
     .data(byYear)
   .enter().append("svg:rect").
	  attr("x", function(datum, index) { return sliderBarX(index); }).
	  attr("y", function(datum) { return sliderBarHeight - sliderBarY(datum); }).
	  attr("height", function(datum) { return sliderBarY(datum); }).
	  attr("width", sliderBarWidth).
	  attr("fill", "#80C080");


	 
	 
	 
	 
	 
	 
	 
	 
	 
});